package model

import (
	"github.com/vsafonkin/crud/common"
)

type Crud struct {
	Id  int
	Row map[string]any
}

type CrudModel struct {
	conn common.DBHandler
}

func NewCrudModel(dbhandler common.DBHandler) CrudModel {
	return CrudModel{
		conn: dbhandler,
	}
}

func (m CrudModel) GetByField(column string, value string, table string) (map[string]any, error) {
	row, err := m.conn.RowByField(column, value, table)
	if err != nil {
		return nil, err
	}
	return row, nil
}
